﻿/*
版权所有：版权所有(C) 2011，刘建新
文件编号：M01_ResUserBll.cs
文件名称：ResUserBll.cs
系统编号：Z0003007
系统名称：通用办公系统
模块编号：M01
模块名称：信息发布
设计文档：IOA_M01信息发布XDE建模.mdx
完成日期：2011-01-05
作　　者：
内容摘要：表[Res_User]业务操作类
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Eis51.CampanyCMS.Model.BaseInfoMng;
using Eis51.CampanyCMS.Model;
using Eis51.CampanyCMS.FrameWork;
using System.Data;
using Eis51.CampanyCMS.Model.Bus.QueryO;
using System.Collections;
using Eis51.CampanyCMS.Access.BaseInfoMng;

namespace Eis51.CampanyCMS.Business.BaseInfoMng
{
    /// <summary>
	/// ResUser的BLL 自定义方法
	/// 该BLL已经生成了基本的业务操作，在自动生成的方法中已经提供了事务机制
	/// </summary>
    public partial class ResUserBLL : BaseBLL<ResUser>
    {
        // <summary>
        /// 保存注册人员
        /// </summary>
        /// <param name="obj"></param>
        public void Submit(ResUser obj)
        {
            if (obj.ResUserId > 0)
            {
                this.Update(obj);
            }
            else
            {
                this.Insert(obj);
            }
        }


        /// <summary>
        /// 登录密码判断
        /// </summary>
        /// <param name="name"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public ResUser Login(string name, string password, string Sellerid)
        {

            IList  it = this.Select();
            foreach (ResUser ad in it)
            {
                if (ad.UserNo.Trim() == name
                    && ad.PassdWod == password
                    && ad.Sellerid == Sellerid)
                {

                    return ad;
                }
            }
            return null;
        }


        /// <summary>
        /// 用户会员注册列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public DataTable Search(ResUserQuery query)
        {
            string sql = "select * from Res_User where 1=1 ";

            if (!string.IsNullOrEmpty(query.Sellerid))
            {
                sql += string.Format(" and Sellerid='{0}'", query.Sellerid);
            }
            if (!string.IsNullOrEmpty(query.UserNo))
            {
                sql += string.Format(" and USER_NO='{0}'", ComSafe.SafeValue(query.UserNo));
            }
            if (!string.IsNullOrEmpty(query.UserNoLike))
            {
                sql += string.Format(" and USER_NO like'%{0}%'", ComSafe.SafeValue(query.UserNoLike));
            }

            sql += string.Format(" and  Create_Date between #{0}# and #{1}#  order by Create_Date desc" ,query.BeginDate ,query.EndDate );

            return this.GetDataTable(sql )  ;
        }

        /// <summary>
        /// 用于Ajax方式的注册，新增用户
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public string AjaxRegedit(ResUser obj)
        {
            ResUserBLL.GetInstance().Submit(obj);
          //  AppContext.CurrentResUser = obj;
            return string.Format("{{Success:{0},MSG:'{1}'}}", "true", "注册成功");
        }

        public ResUser GetUserByEmail(string Email)
        {
            string sql = string.Format( "select * from Res_User where Email='{0}' ",Email )  ;
            DataTable dt = this.GetDataTable(sql);
            if (dt != null && dt.Rows.Count > 0)
            {
                return ResUser.Dr2Obj(dt.Rows[0]);
            }
            return null;
        }

        public ResUser GetUser(string User_NO)
        {
            string sql = string.Format("select * from Res_User where User_NO='{0}' ", User_NO);
            DataTable dt = this.GetDataTable(sql);
            if (dt != null && dt.Rows.Count > 0)
            {
                return ResUser.Dr2Obj(dt.Rows[0]);
            }
            return null;
        }

        public ResUser GetUserByguid(string guid)
        {
            string sql = string.Format("select * from Res_User where guid='{0}' ", guid);
            DataTable dt = this.GetDataTable(sql);
            if (dt != null && dt.Rows.Count > 0)
            {
                return ResUser.Dr2Obj(dt.Rows[0]);
            }
            return null;
        }


    }


    #region 代码自动生成
    /// <summary>
    /// ResUser的BLL
    /// 该BLL已经生成了基本的业务操作，在自动生成的方法中已经提供了事务机制
    /// </summary>
    public partial class ResUserBLL : BaseBLL<ResUser>
    {
        #region 自动生成代码：取得相关实体

        /// <summary>
        /// 方法名称: ResUserBLL
        /// 内容摘要: 构造函数进行初始化
        /// </summary>
        protected ResUserBLL()
        {
        }
        private static volatile ResUserBLL m_instance = null;
        /// <summary>
        /// 方法名称: GetInstance
        /// 内容摘要: 取得 ResUserBLL 对象
        /// </summary>
        /// <returns>返回一个已经存在的实体</returns>
        public static ResUserBLL GetInstance()
        {
            // 通用的必要代码 iBatisNet双校检机制,如果实例不存在
            if (m_instance == null)
            {
                lock (typeof(ResUserBLL))
                {

                    // 如果实例不存在
                    if (m_instance == null)
                    {

                        // 创建一个的实例
                        m_instance = new ResUserBLL();
                    }
                }
            }

            // 返回业务逻辑对象
            return m_instance;
        }

        #endregion

        #region 自动生成代码：基本业务公开函数

        /// <summary>
        /// 方法名称: Get
        /// 内容摘要: 由键值获取一个实体对象
        /// </summary>
        /// <returns>ResUser</returns>
        public ResUser Get(ResUser.Key key)
        {

            return ResUserDao.GetInstance().SelectByID(key);
        }
        /// <summary>
        /// 方法名称: Select
        /// 内容摘要: 基本查询，不带任何条件的查询
        /// </summary>
        public IList Select()
        {
            return ResUserDao.GetInstance().SelectAll();
        }
        /// <summary>
        /// 方法名称: Insert
        /// 内容摘要: 插入一条新纪录
        /// </summary>
        /// <returns>int</returns>
        public int Insert(ResUser obj)
        {
            int result = 0;
            try
            {
                result = ResUserDao.GetInstance().Insert(obj);
            }
            catch (Exception e)
            {
                throw e;
            }
            return result;
        }

        /// <summary>
        /// 方法名称: Update
        /// 内容摘要: 更新一条新纪录
        /// </summary>
        /// <returns>int</returns>
        public int Update(ResUser obj)
        {
            ResUserDao.GetInstance().Update(obj);
            return 1;
        }

        /// <summary>
        /// 方法名称: Delete
        /// 内容摘要: 删除一条新纪录
        /// </summary>
        /// <returns>int</returns>
        public int Delete(ResUser obj)
        {
            bool result = ResUserDao.GetInstance().DeleteByID(new ResUser.Key(obj.ResUserId));
            return result ? 1 : 0;
        }

        #endregion

    }
    #endregion
}